package com.example.babybus.ui.activity

import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
import android.view.View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
import android.view.View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
import com.example.babybus.base.BaseActivity
import com.example.babybus.util.PermissionUtil
import com.example.babybus.util.ToastUtil
import com.example.myapplication.databinding.ActivityMainBbBinding

class MainActivity : BaseActivity() {
    private lateinit var binding: ActivityMainBbBinding


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
    }

    override fun preInit() {
        super.preInit()
        binding = ActivityMainBbBinding.inflate(layoutInflater)

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            window.decorView.systemUiVisibility = (
                    SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            or SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            or SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
                    )

            window.statusBarColor = android.graphics.Color.TRANSPARENT
            window.navigationBarColor = android.graphics.Color.TRANSPARENT
        }
    }

    override fun initData() {
        super.initData()
        if (PermissionUtil.checkLocation(this)) {
            init()
        } else {
            PermissionUtil.requestLocation(this)
        }
    }


    private fun init() {
        // TODO:
    }

    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray
    ) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)

        when (requestCode) {
            PermissionUtil.location_code -> {
                if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    init()
                } else {
                    ToastUtil.toast("用户拒绝授予定位权限")
                }
            }

            else -> {}
        }
    }
}